Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace NullLogger with FakeLogger #14982

Closed
wants to merge 4 commits into from
Closed

Conversation

hishamco
Copy link
Member

@hishamco hishamco commented Jan 3, 2024

No description provided.

Copy link
Member

@Piedone Piedone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FakeLogger collects the log messages so you can later retrieve them, in a test. NullLogger does nothing, nor the mocked loggers. In all of the changed instances, we don't need logging, so NullLogger or a mock was appropriate, while FakeLogger is unnecessary and potentially an impact on performance too.

So, I don't agree with any of the changes here. However, you can check whether NullLogger would be better instead of mock, especially NullLogger<T>.Instance, since it might be cheaper to construct and use then a mock.

@hishamco
Copy link
Member Author

FakeLogger collects the log messages so you can later retrieve them, in a test.

I knew that collecting logs was handy especially in testing, maybe you will notice there's no much value on this PR, but I'm sure FakeLogger is much better than NullLogger because it give us the ability to collect the logs, that's why ASP.NET Core bring it in the latest version

while FakeLogger is unnecessary and potentially an impact on performance too

This is true if we use it in the code-base, but I used for testing ONLY

@Piedone
Copy link
Member

Piedone commented Jan 10, 2024

But we don't do anything with the logs. If we were, then FakeLogger would be useful. However, for the instances you changed, no logging is required, the mocks and NullLogger were only injected to not have the code break due to null references. So, using FakeLogger causes unnecessary overhead but brings no value.

I understand this is only about testing, but test execution performance matters too.

@hishamco
Copy link
Member Author

I will close this for now, but once when need the logs records on the testing FakeLogger is our choice :)

@hishamco hishamco closed this Jan 10, 2024
@Piedone
Copy link
Member

Piedone commented Jan 10, 2024

Then absolutely, just these are not such cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants